﻿// ------------------------------------------------------------------------------------
// File:		GetTests.cs
// Created:	27/02/2012 3:07 PM
// 
// Last modified:	tri @ 28/02/2012 11:26 AM
// ------------------------------------------------------------------------------------

namespace EntityFramework.OT.Demo
{
    using System.Collections.Generic;
    using System.Linq;

    using EntityFramework.OT.Demo.Data;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class GetTests
    {
        #region Public Methods

        /// <summary>
        ///     Get the first employee from the DB
        /// </summary>
        /// <returns> </returns>
        public static Employee GetFirstEmployee()
        {
            using (var context = new NorthWindEntities())
            {
                var employee = context.Employees.First();
                Assert.IsNotNull(employee);
                employee.StartTracking();
                return employee;
            }
        }

        public static ObjectOperationTracker GetFirstEmployeeTracker()
        {
            using (var context = new NorthWindEntities())
            {
                var employee = context.Employees.First();
                Assert.IsNotNull(employee);
                employee.StartTracking();
                return employee.OperationTracker;
            }
        }

        public static List<Order> GetCustomerOrders(string customerID)
        {
            using (var context = new NorthWindEntities())
            {
                return context.Orders.Where(o => o.CustomerID == customerID).ToList();
            }
        }

        /// <summary>
        ///     Get the first customer from the DB
        /// </summary>
        /// <returns> </returns>
        public static Customer GetFirstCustomer()
        {
            using (var context = new NorthWindEntities())
            {
                var customer = context.Customers.First();
                Assert.IsNotNull(customer);
                customer.StartTracking();
                return customer;
            }
        }

        [TestMethod]
        public void TestGetEmployee()
        {
            var employee = GetFirstEmployee();
            Assert.IsNotNull(employee);
        }

        [TestMethod]
        public void TestGetEmployeeTracker()
        {
            var employee = GetFirstEmployeeTracker().ApplyChanges();
            Assert.IsNotNull(employee);
        }
        #endregion
    }
}